package gns

import (
	"io"
	"net/http"
	"os"

	"gitee.com/liumou_site/logger"
)

// DownloadFile 从指定的URL下载文件并保存到本地路径。
func DownloadFile(url string, save string) bool {
	logger.Debug("Downloading URL: %s", url)
	logger.Debug("Save File Path: %s", save)
	res, err := http.Get(url)
	status := false
	if err != nil {
		return false
	} else {
		f, err := os.Create(save)
		if err != nil {
			return false
		} else {
			_, err := io.Copy(f, res.Body)
			if err != nil {
				return false
			}
			status = true
		}
	}
	logger.Info("End of download")
	return status
}
